Skip to content

refactor: Align nonce computation with other mobile SDKs#1118

Merged
NandanPrabhu merged 8 commits intomasterfrom
nonce_fixes
Mar 18, 2026
Merged

refactor: Align nonce computation with other mobile SDKs#1118
NandanPrabhu merged 8 commits intomasterfrom
nonce_fixes

Conversation

@NandanPrabhu
Copy link
Copy Markdown
Contributor

@NandanPrabhu NandanPrabhu commented Mar 16, 2026

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Nonce computation is refactored to match other SDKs in following steps

  • by the value user passes through func nonce(_ nonce: String) -> Self of WebAuth
  • by the value user passes through parameters func parameters(_ parameters: [String: String]) -> Self
  • if value is not passed through either ways. We compute default value for nonce same way state is computed
  • Now nonce will always be non optional value and it is ensure different authorization request from same Auth0WebAuth instance will always have different nonce and state values

📎 References

🎯 Testing

Unit tests updated to add coverage for code for nonce computation refactoring

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Auth0WebAuth to persist and propagate state/nonce values through the web auth flow (including authorize URL construction and ID token validation), and adjusts the test suite accordingly.

Changes:

  • Generate and store default state and nonce in Auth0WebAuth.parameters when missing.
  • Thread nonce through start() into buildAuthorizeURL(...), and pass it into the PKCE handler for ID token validation.
  • Update WebAuthSpec to exercise the new nonce/state behavior and to pass a nonce into buildAuthorizeURL(...) in URL-building tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
Auth0/Auth0WebAuth.swift Adds cached generation for state/nonce, threads nonce into authorize URL building, and uses nonce for PKCE/ID token validation.
Auth0Tests/WebAuthSpec.swift Updates authorize URL tests and adds/adjusts expectations around state/nonce generation and persistence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

(cherry picked from commit 9cee5402bf20e6210d4cfcfdcf506b3bc30aab7d)
@sanchitmehtagit sanchitmehtagit added review:medium Medium review labels Mar 17, 2026
Copy link
Copy Markdown
Contributor

@sanchitmehtagit sanchitmehtagit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Could we please add context/background too on PR description and better PR title

Copy link
Copy Markdown
Contributor

@sanchitmehtagit sanchitmehtagit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 NIT

@NandanPrabhu NandanPrabhu merged commit 0b756f7 into master Mar 18, 2026
11 of 12 checks passed
@NandanPrabhu NandanPrabhu deleted the nonce_fixes branch March 18, 2026 08:49
@NandanPrabhu NandanPrabhu changed the title Nonce computation changes Nonce computation refactored to match other mobile SDKs Mar 18, 2026
@sanchitmehtagit sanchitmehtagit changed the title Nonce computation refactored to match other mobile SDKs chore: Refactor nonce computation to align with other mobile SDKs Mar 18, 2026
@sanchitmehtagit sanchitmehtagit changed the title chore: Refactor nonce computation to align with other mobile SDKs fix: Refactor nonce computation to align with other mobile SDKs Mar 18, 2026
@sanchitmehtagit sanchitmehtagit changed the title fix: Refactor nonce computation to align with other mobile SDKs refactor: Align nonce computation with other mobile SDKs Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:medium Medium review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants